<?php

namespace app\system\model\customer;

use app\system\model\Admin;
use app\system\model\business\Quotation;
use app\system\model\corp\Supplier;
use app\system\model\Customer;
use think\Model;


class Order extends Model {
    /**
     * @var string 自动写入时间戳
     */
    protected $autoWriteTimestamp = false;


    public $name = 'customer_order';

    public function getStatusAttr($value){
        return $value != '' && $value != null ? explode(',', $value) : [];
    }

    public function detail(){
        return $this->hasMany(OrderList::class, 'order_id', 'id');
    }

    public function bill(){
        return $this->hasMany(OrderBill::class, 'order_id', 'id');
    }


    public function customer(){
        return $this->hasOne(Customer::class, 'id', 'customer_id');
    }

    public function supplier(){
        return $this->hasOne(Supplier::class, 'id', 'supplier_id');
    }


    public function admin(){
        return $this->hasOne(Admin::class, 'id', 'admin_id');
    }

    public function quotation(){
        return $this->hasMany(Quotation::class, 'business_id', 'id');
    }



//    public function getpayAmountTextAttr($value, $data){
//        return Numberala::formatNumber($data['pay_amount']) . ' CNY';
//    }



    public function getCreateDateTextAttr($value, $data){
        return date('Y-m-d', $data['create_time']);
    }

    public function getCreateTimeTextAttr($value, $data){
        return date('H:i:s', $data['create_time']);
    }


}